package com.yilu.driver.mvp.presenter;


import android.content.Context;

import com.is.common.retrofitrxcache.RxCacheResult;
import com.is.common.rx.RxSubscriber;
import com.yilu.driver.entity.DeleteTraineeResponse;
import com.yilu.driver.entity.TraineeDropResponse;
import com.yilu.driver.entity.TraineeInfoResponse;
import com.yilu.driver.mvp.contract.TraineeInfoContract;

import org.json.JSONObject;


/**
 * @author Administrator
 * @date 2017/4/12 0012
 */

public class TraineeInfoPresenter extends TraineeInfoContract.Presenter {
    private Context mContext;

    public TraineeInfoPresenter(Context mContext) {
        this.mContext = mContext;
    }

    @Override
    public void getTraineeInfo(JSONObject json) {
        mRxManager.add(mModel.getTraineeInfo(json).subscribe(new RxSubscriber<RxCacheResult<TraineeInfoResponse>>(mContext, "加载中", true) {
            @Override
            protected void _onNext(RxCacheResult<TraineeInfoResponse> traineeInfoResponseRxCacheResult) {
                mView.returnTraineeInfo(traineeInfoResponseRxCacheResult.getResultModel());
            }

            @Override
            protected void _onError(String message) {

            }
        }));
    }

    @Override
    public void dropOutTrainee(JSONObject json) {
        mRxManager.add(mModel.dropOutTrainee(json).subscribe(new RxSubscriber<RxCacheResult<TraineeDropResponse>>(mContext, "退学中", true) {
            @Override
            protected void _onNext(RxCacheResult<TraineeDropResponse> dropResponseRxCacheResult) {
                mView.returnDropOutTrainee(dropResponseRxCacheResult.getResultModel());
            }

            @Override
            protected void _onError(String message) {

            }
        }));
    }

    @Override
    public void deleteTrainee(JSONObject json) {
        mRxManager.add(mModel.deleteTrainee(json).subscribe(new RxSubscriber<RxCacheResult<DeleteTraineeResponse>>(mContext, "删除中", true) {
            @Override
            protected void _onNext(RxCacheResult<DeleteTraineeResponse> deleteTraineeResponseRxCacheResult) {
                mView.returnDeleteTrainee(deleteTraineeResponseRxCacheResult.getResultModel());
            }

            @Override
            protected void _onError(String message) {

            }
        }));
    }
}
